﻿<%@ WebHandler Language="C#" Class="Build_thumbnail" %>

using System;
using System.Web;
using System.Web.SessionState;
using System.Collections;

public class Build_thumbnail : IHttpHandler, IRequiresSessionState{

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        /* 管理员验证 */
        //  if (!Admins.IsLogin(true))
        //     Utils.ShowEnd(context, "-2");

        int x1 = 0;
        int x2 = 0;
        int y1 = 0;
        int y2 = 0;
        int width = 0;
        int height = 0;
        int img_b_width = 0;
        int img_b_height = 0;
        try {
            x1 = Convert.ToInt32(context.Request.Params["x1"].ToString());
            x2 = Convert.ToInt32(context.Request.Params["x2"].ToString());
            y1 = Convert.ToInt32(context.Request.Params["y1"].ToString());
            y2 = Convert.ToInt32(context.Request.Params["y2"].ToString());
            width = Convert.ToInt32(context.Request.Params["width"].ToString());
            height = Convert.ToInt32(context.Request.Params["height"].ToString());

            img_b_width = Convert.ToInt32(context.Request.Params["img_b_width"].ToString());
            img_b_height = Convert.ToInt32(context.Request.Params["img_b_height"].ToString());
        }
        catch {
                Utils.ShowEnd(context, 1);
        }

        string imgPath = context.Request.Params["imgPath"].ToString();
        if (imgPath.IndexOf('?') > 0)
            imgPath=  imgPath.Remove(imgPath.IndexOf('?'));
        string size_list_str=context.Request.Params["select_size_list"].ToString();
        string[] sArray = size_list_str.Split(',');

        ArrayList select_size_list = new ArrayList();
        foreach (string i in sArray)
            select_size_list.Add(i.ToString());
        int status= Thumbnail.MakeThumbnailSelect(context.Server.MapPath(imgPath), context.Server.MapPath(imgPath.Replace(".jpg", "__p.jpg")), x1, y1, width, height, select_size_list, 100);

        Utils.ShowEnd(context, status);
    }

    public bool IsReusable {
        get {
            return false;
        }
    }



}